package $17_throwable;

public class TryCatchFinally {
	public static void main(String[]args) {
	    int i = 6;
	    int j = 0;
	    try {
	        //可能出现异常的代码
	        int result = divide(i, j);//光标移动到报错处可选择一键装备try{}catch(){}
			System.out.println(i + " / " + j + " = " + result);
			//当检测到错误，会创建一个对象（new ArithmeticException()）
	    }catch(ArithmeticException e){ //匹配对象ArithmeticException e = new ArihtmeticException();
	        //异常提示
	        System.out.println("不能除0");
	        System.out.println("-----------------------------------------------------");
	        
	        System.out.println(e.getMessage());    //获取到异常的简短消息
	        System.out.println("-----------------------------------------------------");
	        
	        System.out.println(e.toString());      //获取到异常的类型和消息
	        System.out.println("-----------------------------------------------------");
	        
	        e.printStackTrace();                   //获取到异常的类型、消息和所处位置
	        System.out.println("-----------------------------------------------------");
        }finally {
	        //无论是否出现异常都会执行
	        System.out.println("我是finally代码块中的内容");
	    }
	    System.out.println("看看我执行了没");
	}
	public static int divide(int i, int j) {
		int result = i / j;
		return result;
	}
}
